package com.example.kafkabasic.producer;

import com.example.kafkabasic.KafkaBasicApplication;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@RequiredArgsConstructor
@Component
public class KafkaProducer {

    private final KafkaTemplate<String, String> kafkaTemplate;

    @Scheduled(fixedDelay = 1000)
    public void senderTopic1() {
        String currentTime = "currentTme topic1:" + System.currentTimeMillis();
        log.info("start send current time: {}", currentTime);
        kafkaTemplate.send("topic-1", currentTime);
    }

    @Scheduled(fixedDelay = 5000)
    public void senderTopic2() {
        String currentTime = "currentTme topci2:" + System.currentTimeMillis();
        log.info("start send current time: {}", currentTime);
        kafkaTemplate.send("topic-1", currentTime);
    }
}
